this is a lot more complicated than the original implementation, so it's hard for me to tell if there a functional changes.

why do we need to special case ANNOTATED_SORTER? couldn't the difference between ANNOTATED_SORTER and the other sorters be put in the implementation of ANNOTATED_SORTER?