Refactore the log and exception