Fix for incorrect weighted mean calculation