Improve flag checks