Update client.js

Adds a cleanup function on insert and update