fix logging statements for input/output
slightly rewrite loop logic