fix stack-allocated global variables, and indexing arrays