Test coverage and whatnot

including refactoring to make testing easier/possible.