added median fucntion

To spec, I hope!