Added code from Programming Lecture #16.