Final function submission for Programming Assignment 2