code reorganization, minor refactors