some reorganization and cleanup