cleaned up code to match blog post