added flag checking