More tests and bugfixes