Test and other fixes

These are some commits from a while ago that never made it upstream. They include some fixes to make the tests more robust, added tests, and fixed test signatures which also need to go into the RFC.