Fixed off-by-one errors that were occuring both at the start and end of the cycle calculation