Implementation of the required functions for Programming Assignment 2