solve problem 3 properly