Removed code duplication in replaceRangeSet