re-wrote the sum function

was working in node, but got a weird error when tried to run the whole
file from the command line