added code from book