Refactor to shorten and clean functions
Merge branch 'master' into gh-pages