Add missing 'local' keyword on internal helper functions to prevent overwriting