Fixed a tricky intermittant multi-thread problem and some failing unit tests.