Make loop time-based instead of count-based