finished ex. 2 of assignment 3