Refactor synchronize script