Fixed issue with detecting EOF