based on https://gist.github.com/nowl/828013 not used in awhile—may be broken due to language changes.