almost full rewrite