some fixes for while loop