Merge josh's exit dir patch (bug #2995)