Nested discovery fixes

Sorry for the lack of tests.  Hopefully I'll get to this tomorrow.
could we use a type variable instead?