restructuring, minor bugfixes