bug fixes - file rewriting
file rewrite test