some useful code snippets from text book(The way to go)