Bugfixes resulting from code restructure