Solution to Coursera Assignment