moved some input/output logic to separate methods