fixed a bug that window in sample string is adjusted after first while loop