Fixed flag processing to prevent crashing