moved sleep into main loop