Slight bugfixes in unit-tests; slight refactoring