Fixing allocation of array with variable size by replacing with vector and resize/dynamic allocation