Refactors login_chdir