Getting sleep mode to work properly