added wait_eof method