patch https://gist.github.com/michaelcontento/5443151