Fixes failing tests

The algorithm for finding the matching descendent is horribly
inefficient.
Adds ReplaceDescendentNotFound test.