Working version of solution to programming assignment 2.