Clever file handling