add some codes from chap5