Refactor dg.run.