logic for flags controller