More tests, fix a few bugs