fix handling end of input