A project inspired by code at https://gist.github.com/stonegao/1335696