More tests, fix small bugs