restrict scope of lastPos to id_loop()