Cleaned up sorting code location and style