fix undefined sleep
more test and fixes
fix