Refactoring code and making log messages more clear