Refactor error callbacks