Reorganization and bugfixes