Bugfixes due to code reorganizing