Implementing problem 5.