cleanup of replica set code and added tests.