Update to properly free memory
Updated for fully dynamic array initialization
Fixed bug