modified by jack for fix the bug of not running out of while loop when
receiving the data