refactored swarm processing loop