bug fixes in sortRange