Changed the sleepfor to be called in an onidle