Fix crashing issue after changing directories too much