added error handling