Bug fix in weighted.median calculation