Implemented problem 3.