Some more refactoring, and add config class.