if timeleft>0 delay timeleft
I'm not sure that DELAY is the best command to use (depending on the situation of course). Most of the time you are going to want to let the CPU do other tasks while waiting but I don't think that the DELAY command allows this. A better setup would be to use a timer and WaitTimer command.