refactoring to make it a bit more functional in style