Implemented toArray on mapreduce phase