more error handling improvement