refactored the code, one log file for all output