fixed off-by-one bug in computing median