put output to array instead of global variable