cleanup
moved flag def outside of for loop