More unit tests and code fixes to tighten things up a bit