at first it struck me that you hadn't formatted your code as code; so I have edited your post please read
with that out of the way, the colourising code formatting, makes it clear an obvious problem in your code
notice how the colour at the bottom is not the colour at the start...