Reorganization and few bugfixes