replaced some malloc/free usage with global_alloc_array/global_free_array (nw)