fix and implement sleep api