got rid of the accumulator array; wrapped all the code into a function which makes it run faster; the memory usage has gone up slightly