complete the solution from problem 5