cleaned up ranges code