some code reorganization