Refactor config system

This is only the first step for a new config system, the code is still ugly and will be cleaned up step by step