Improve dynamic array implementation