Fixed replication errors
Added tests for replication