When trying to get browser from frame, occasionally a null pointer was occurring as per #493.
Cleanup logic to handle null pointer, also simplify as was a little convoluted.