refactored particle parsing code to be simplier and more comapact