Update umd

This merges in a few small fixes where I'd misunderstood the code I was copying (thanks to @domenic for fixing).  It also adds unit tests.