fixed a threading race condition problem

race condition resulted in ArrayOutOfBoundsException