add OutputFile logic (merge from SVN master r19434/r19345).
merge minor changes from master.