generalized file handling