fixed check in upsert