Completed function for assignment 2