Added testing of sorting feature
Slightly refactored code and formatting