it is not clear from what seems to be the somewhat misformatted code snippit what you are dealing with (for example, Part[xpos, i] - Dynamic has no meaning). (Advice, use the MCode formatting to present your code -- it's the Mathematica icon in the formatting bar.)
So perhaps present some more detail -- properly formatted in an MCode cell and perferrably a simplified example of what you are encountering -- for what you are trying to achieve.