init, copy from https://gist.github.com/chaifeng/6240787