fixed crashy error handling