add some codes from chap4