some refactoring to simplify testing