implemented problem 4