To make it hopefully easier to understand the commonality
of this function and its handlers have the handlers be
defined at the top of the function and use the common list
in the node iteration routine when resetting/matching.
Change-Id: I288eb548172b2f6f35e2bd90683f2065d3aa02dc