Code of coursera assignment 2.