Many places in code use the
'#theme' => 'token_tree' to render a 'Browse available tokens' link. This immediately just calls 'token_tree_link'. I am not sure why this was done earlier but it doesn't seem necessary.
Replace calls to 'token_tree' with 'token_tree_link'. This immediately makes code a bit more understandable and removes some of the confusing bits.
User interface changes
You should use 'token_tree_link' to render the link.
'#theme' => 'token_tree' with
'#dialog' => TRUE will no longer render the link.
Data model changes