If you want to use sleep you should first spawn() off the code so there is no chance of it interrupting anything else.