completed coding for ex4