FIX: avoid use-after-free error caused by a static iterator