Added better last dir logic, better debug logic.