reimplement a lot of code
Merge branch 'master' into gh-pages