Refactoring and added basic config file support