added check for empty dir