changed to use more functional style