More extensive error handling