Improved flag validation