converted some malloc()/free() usage to dynamic_array/dynamic_buffer (nw)