Fixed flag processing bug