Added dynamic array and fixed other issue.

The function write_from_taskbuf was kinda reversed