Complete pull request

Tried to use the nifty GitHub edit feature for that pull request. Fail. Only edited a single file.
So, here's the complete thing.  With a header changes and fixed tests.