Bugfixing in preparation of unit testing