added error handling
added error handling