minor refactoring and reorganization