Made im_waiting_for_flush take a std::set, avoided (mutually) recursive calls to im_waiting_for_flush.