No need to recalculate the interval in the loop, and some error handling