Flags were wrongly overwritten