moved sleep out of if(..) as it might be optimised away