Makes the code cleaner to read and more resilient to changes Fixes https://jira.coreos.com/browse/QUAY-940
Also adds testing to ensure we don't break this again