fixed segmentation fault for more than 2 agents