Code snippets from http://0branch.com/notes/tco-cl.html.