Bug fixes
More bugfix and reorganization