Refine code
Add check for -d argument

- the orginal exception handle was too general.