Fixed various issues related to allocating arrays.