my not very elegant solution to problem 6. Passing the object as the
prev value is much more elegant and eleminates my closure.