refactor end of chapt 3