moved variable inside while block