making addtomodel's upsert process more robust