added error handling and output