median/mad bug fix