Forked from David McNeil's excellent repo + blog post.