fixed a flag setting bug