Refactored code for clicking on file tree