Completed ex1 of assignment 4