Fixed a bug in the native API foreach functions, and made post-GC callbacks run