Unit tests and bugfixes where needed