fix uninitialized variable being used to index array