restructure file IO