fix off by one errors in loop ranges: use 'until' instead of 'to'