Make a sort_classes function