refine particle code