Updated to remove use of C99 VLAs