Working version of upsert, currently ignoring null values