Thank you very much for pointing out these errors.
I also didn't realize that my $var outside of Blocks was a file-wide declaration, I assumed its scope was limited to "Non-Blocks". Now it makes so much more sense =) Thank you for pointing that out!
I'm still in the process of rewriting the improved version so this helps me a lot.