Refactored
Changed midpoint calculation
Plot for median