minor refactors and code cleanup