fixed timing error, where sleep time became < 0