refactor flush and quit channel