Slightly better handling of file modes
Some cosmetic fixes.