AngularJS object cleanup before insert or update (FIX issue #27)

Adds a cleanup function on insert and update