More cleanup for median function