Fixes incorrect handling of nested global close tag

Includes tests to verify correct functionality
Merge pull request #1 from arjank/master

Fixes incorrect handling of nested global close tag