cleaned up sorting