Implemented sorting of particles