Refactored the data insert to be an upsert