Completed functions for Programming Assignment 2