Refactor copy_and_run so that it uses a single code base instead of