Refactor sortData() again to remove if statement