completed functions for Programming Assignment 2