map was pretty ugly to write...it feels like it's not written in functional style