Refactor config loading routine