Added stable sort, and TokenReplacer class