New function find_smallest_matching_node().  Not sure if correct, needs testing.