added check for particle array size to optimize3