added rest of Ch5 code