Fix detect edge

Move detectEdge to the @fun level.

This branch also re-enables the 'blow-up' detection that was present in V4.