refactored the wakeup function