Bugfixes from refactor