some code gardening and minor refactors