Update the instance state at the end of the while loop

Update the instance state at the end of the while loop
Fixed print syntax