completely implement problem 6