trying to fix error where it does return if reached eof