Fix flags check logic