Important bugfix in weighted avarage function