finally solved problem 18