fixing the code for sharded replication env and cleaning the code