Move processing of components into a helper function.

Also, severely reduce the logic and nesting that is required for
processing a single component.