Add unit test infrastructure, plus a few bugfixes and PEP8 cleanups.