minor refactoring to move some internals around