Re-implement rewrite module using rewrite_cell