refactoring: extract the computation of sort from KItem constructor to helper method