updated file io again to make it better