What exactly is the purpose of the script? How is the sorting supposed to work, and how does it currently work?