Refactored the code, fixed bugs so that it properly sorts, and added a few classes