prefer functional style

i am trying to use fewer loops i guess