small bugfixes all around code