pairs() in lua does not loop in order, switched to ipairs() to resolve bug