Refactoring and improve logging system