Added code to calculate cluster quality.