Completed ex3 of assignment 4