Another thought, which I know doesn't address the sort issue. Since there are only ever two values, you're really just making two groups, with a lot of processing going on in-between. So have you considered just grepping the values? It might run a whole lot faster.