Median calculation was all wrong

Fixes #2