Fixes always a bug. Now states are saved preferentially to the selected name in the tree.