Some code snippets from following Kevin Baird's book