Fix issue with range being upper exclusive