Rolled back to original rewrite_mod. originaly modified for test purposes