fixed trailing slash problem with -d and added another case for the output

- if there is a trailing slash in the argument of option -d, th script won't work, so I get rid of the trailing slash
- added a 3rd case for the output to honor the -d option