Replication script fixes