fixed bug with upsert