current code finally refactored.
Merge branch 'master' into gh-pages