median calculation was wrong