When posting code, please use the highlight tags to preserve formatting.

You're going to have to debug your code to figure out where its execution differs from your expectations. Recommended...