more robust error handling