Two calls here to resolveSortDirection could me merged into one if moved after the if/else block.