factored out the delay code into a function