More unit test & bugfixes