SortDirection could have been cached cached earlier if isTableMin and isTableMax had been tested separately the first time -- in an "if...else if...else {return plan;}" block.