fixed the upsert bug