Working skeleton based on https://gist.github.com/mpriour/5147802