refactored sleep