Lots of little fixes and features

Resurrected this pull now that generalized mocking test functions are available.