enhance error handling