fixed cache replication and some refactor