refactoring the file access functions, merging stuff from experimental