Fix found errors that happend during rewrite