final bugfixes to make refactoring work