Cleaned up formatting and the sorting code