Added scanning before going to sleep