improved student sorting code