tidying up file handling