Updated funciton for Programming Assignment 2