Refactored TreeView events code