added code from en.wikibooks.org