Improved Error Handling

provided more detailed error handling.