You are also using system.tag.browse() in the foreground. Like any other script function that calls out to the gateway, it should be called in a background script, and UI interaction handled with .invokeLater(). See this topic:
I make an exception for button actionPerformed scripts (short ones), as an operator can expect some processing delay upon their command.