base code from book added