cleaner way to do file IO