use basename for prefixes
fix typo
use dirname consistently
handle " D" status