fixed replication (backport pr #175 to master branch)