several fixes to improve directory handling