moved file i/o to a separate file