fix using while loop as faster