move TreeNode exploration into its own function, fix performance regression