More unittests, bugfixes