move some globals to statics in loop