finally solved problem 12