improvement to input routine

closes file before reproducing error