added end of file checking