Finished internal rewrite but removed reference implementation.