improve matchRanges method in projection code