After Script in Subprogram the cobot stops for a second and continues

As the title says I have a script in a subprogram but after that it just sits there for a second and goes further. While sanding this is not ideal for the cobot to stop at certain spots.

Is it the subprogram that does that or the script?

Here is the script:
global move_thread_flag_13=0
thread move_thread_13():
enter_critical
move_thread_flag_13 = 1
local towardsPos=calculate_point_to_move_towards(get_forward_kin(), [NewX,newY,0.0], var_1)
movel(towardsPos, a=1.2, v=0.025)
move_thread_flag_13 = 2
exit_critical
end
move_thread_flag_13 = 0
move_thread_han_13 = run move_thread_13()
while (True):
sleep(1.0E-10)
if (move_thread_flag_13 > 1):
join move_thread_han_13
break
end
sync()
end

its just the direction node in script and i made the distance variable. So i dont think thats the problem
after the subprogram i also have a variable waypoint.