Rewrite master

Merge rewrite progress into master.