Completed ex5 of assignment 2