Fixed dynamic array

It might work now, without memory leaks.