added condition to sleep routine