Credit @alunny for the original implementation

Thanks @rioter for the [prod](https://twitter.com/rioter/status/358043107163508736).