Implemented problem 4.