refactoring towards a more functional style
refactoring towards a more functional style