Optimizing tick function

I have the following tick function:

scoreboard players enable @a setHome scoreboard players enable @a home

execute as @a[scores={setHome=1}] run execute at @s run function homes:sethome/set

execute as @e[tag=target,limit=1] run function homes:home/tp

execute as @a[tag=teleporting] run return fail execute as @a[scores={home=1},limit=1,sort=random] run function homes:home/init

The line "execute as @e[tag=target,limit=1] run function homes:home/tp" only needs to be run if there is a player tagged with "teleporting", and the line "execute as @a[scores={home=1},limit=1,sort=random] run function homes:home/init" should only be run if there is not a player tagged with "teleporting". How can i achieve this? Right now the line "execute as @e[tag=target,limit=1] run function homes:home/tp" is always run.

Continue to help post