Rewrite engine section

Started working on rewrite engine section.
Minor fix at beginning with undo button