Refactor core

This is a preparation for the redesign of the configuration system. Though there are still remaining bad smells in the codebase, I want this to be merged while it can track the upstream.