More tests & a couple bugfixes.