updated code for 8 agents