Some tests and bugfixes