See notes in config module, this can be simplified and made less brittle in one go.