a better solution from a blog post