upsert FTW. Compiles. No idea if worky.
bugfixes
Merge branch 'upsert' into dev