Coding example from a book with my changes.