add some codes from book.