I can't discover in your script how kixtart check or account exist or not.
The add/delete/active part is clear for me.