Implemented given code from ch9.9 in book