Tests and refactoring for replication issue #14