Fix a bug and use -d to test the directory