refactoring SWARM and test for SWARM