Test cov to 90

Lots of new specs to get the test coverage up to ~94%, a few small refactorings along the way to make the code a) more readable, b) more threadsafe, and c) more testable