Rewrite

Moving into master branch, legacy version moved to legacy branch.