refactored to a more compositional form