Error logging improved