add code for chapter7 and chapter8