Add more robust error handling to the insert