minor code refactoring/reorganization