refactors to support testing