Refactor list sorting code into modules to improve readability and code reuse.
Add some more useful debug data