refactoring to a more compositional style