Implemented problem 2