I wanted to merge the code asap so I could use it in the leojs project. If there are any problems I apologize in advance :-)
Please report any problems immediately.
Having made the standard disclaimers, new code is much better than the old: simpler and more flexible.