Added config file and some refactoring