Change SHARED function to use a safe traversal when modifying a variable