Fixed a bug that allowed a selection to go out of range