keep a local loop count since machines_count is modified during the loop