refactored particle swarm