Fixing a bug in the median-of-three function