Some tentative refactoring to config
Fixes many of the config loading issues.