final version of problem 3