Refactoring functionality to order by column