Provided by ted's earlier commit; added tests and tweaks in r66. Note that this could use a speed-up.
Provided by ted's earlier commit; added tests and tweaks in r66. Note that this could use a speed-up.