added flag_t, fixed Bugs