Improve directory checking