code cleanup (by using function to reset delay counter)