functional improvement for directory handling