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...
This doesn't discover a 'var' dimension yet, right?