Rewrite logic.