more defensive error handling