queue flush implementation and handler