sorting working correctly