Fix segfault and little refactoring in `watch_directory_tree`