bug fix, need more tests for replication