Fix to the upsert sql generation.
Code cleanup.