replaced sleep with withforcompletion parameter