Updated with code from the blog post