replaced explicit recursion with map; removed accumulator