Fixes incorrect handling of nested global close tag

Includes tests to verify correct functionality