Fix median calculation

 - Fix for order of operations and zero based sets