add improved error handling.