add some codes from chap3