Haha, the nonsensical justification aside the cause for my wonky sorting seems to be correct and it should now do what it's supposed to.