Refactoring. Error logging