replaced for loops with maps where appropriate