Some minor fixes and refactoring to min/max ranges