Fixed averaging bug