Refactored sort (nukesort) function. Passes the tests.