added common error handling
modified error handling