upstream changes: re-implement the '-d' option