A few small bugfixes to allow unittests to be run