Changed directory check to use -d