Refactorings and added one more flag to emit rewritings.
Added some debug helpers.
Added debug printers jrag.