Refactor out unneeded code around ranges and boundaries