Fixed some errors in leader selection and averaging method.