Refactored session sorting to be testable.