When posting code, use the code tag. It makes code easier to scroll through and easier to pull in to the IDE.
It looks like you did not post the entire sketch.
You posted code. Does it do what you want. If so, YAY!
If not, please explain what you expect it to do and what it actually does that differs from your expectations.