careful add two while loop to boost performance

good catch