Extracted function to describe some complex logic

Attempted to figure some other stuff out... and failed for the time
being.