Improve box() around edge cases
Refactor out unneeded code around ranges and boundaries