trying to fix the toggle flag logic