Fixed log level mismatch problem and refactored code