Refactoring and add log files