adding correct log message and refactoring