improved directory check