almost finished rewrite engine section

Later need to make it better