fixed upsert to return correct result