code change from gleasy to add master-master replication support