Add tests for swarm stack manipulation and refactor