a timer and sleep function