File handling fixes

Although you indicated that you had already pulled these changes, here's a formal PR.