Refactor the emacs root directory finding code