Major refactoring of files and config handling