added error handling.