enhanced/fixed error handling