switching out recursion for map/reduce