restructuring for rewrite