fixing sleep loop