Fixed bad upsert behavior