some reorganization & refactoring