Move flag logic into controller