Refactor sort classes and write tests for them.