Don't use static variables and clean up the creation of the base 'function' in the tikz file.