move delay into loop function