final function for task 1 of assignment 1