The previous version was a mistakenly old.
Before this initial commit, I worked on the code in a github gist. The code in this commit comes from this gist commit: https://gist.github.com/2725916/ce58be848998aa93572f99e62f2e39e06db9463a