Fixing a whole bunch of off-by-one errors