Sync script: added merge function