I struggled with the sleep function for awhile too, but here's some additional comments and some code that works for me: