Completed ex4 of assignment 4