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...