Changed variance algorithm to remove numerical instability according to http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
Added coherency cost function