added final loop count condition to while loop