code reorganization and documentation fixes