fix prepopulation

Moved global variables to top of function and properly instantiated
array.