Updated error handling
merged changes