implement Programming Assignment 2 functions