Update discovery

This code is pretty ugly.  I think it's getting less ugly but it's still pretty incomprehensible.

It does works significantly better though...
These might generate some noise in the tests?