Config and db refactor