Fix a 'out of range' bug