Implemented problem 1