Simplify median calculation