modified based from a blog post devjs