Jason (or Sudip?), you might want to use a more descriptive subject since 'program is not working' defines probably 98% of the posts in this space.
Not sure it's possible to answer your question intelligently without seeing other parts of the program and variable definitions. How would we know the significance of all those variables and what is really happening at the end?
Have you tried running this through debugger and simply checking what effect each command has? This doesn't seem to be very complex code, although again - it's hard to tell from just one fragment.