Improved error handling
Merged