How to schedule a function while retaining context?

I'm making a waypoint datapack that uses end gateways to acheive teleportation. When the player wants to teleport, the datapack spawns a gateway above them, sets its destination nbt data to that of the players stored waypoint, and then teleports the player into the gateway. the problem im having is destroying the portal after teleportation. if i add a line to destroy the portal in the same function that creates it then the player is not teleported. but if i try to schedule it to be broken a second later it also doesnt work. i think this is because when you schedule a function it is run at world spawn? heres the logic for creating the gateway: tp ~ 100.5 ~ setblock ~ 100 ~ minecraft:end_gateway{exit_portal: [I; 0, 0, 0], ExactTeleport:1b} execute store result block ~ 100 ~ exit_portal[0] int 1 run data get storage cords X execute store result block ~ 100 ~ exit_portal[1] int 1 run data get storage cords Y execute store result block ~ 100 ~ exit_portal[2] int 1 run data get storage cords Z
Continue to help post