Sync script: refactoring