fixed several issues with update and sync of total

Several errors were thrown with memory overload.  I resolved this by
moving the function call outside to a new function.

I also implemented the necessary code to check if local variables had
been created previously, if they have not, they are created with default
values.