Re-added the sleep function

you need the script function to get thing to work. Unless you use it,
the last submission might not be added.
Moved the increase of the ID

Moved the increase of the ID to the end of the code to avoid unwanted
increase when the code is bugged