Sleep timer code with queue