Fixed check in sort routine when specifying limits.

The check for start/end was incorrect. Also, added new unit test
test_sort.py