Fix division by zero bug in corner detectors

Finally fixes issue #471 and #474.