Initial code.

Based on: https://gist.github.com/rafaelmartins/bb415543ab5fad84b36e