rewrite multi_stage