refactor particle wraparound code