refactored swapping code.
Merge branch 'master' into gh-pages
publishing