I made a few changes to this code to make it work in my environment. I found that sometimes it was using the id field for the primary key and sometimes it uses clientID field for primary key. They don't always match.
Some other fixes were made for updates. I hope you pull them in. Thanks for starting this - it really saved my bacon!
Fixed several problems that prevented it from working