Changed find_unstable_nodes to use pattern matching on input.