fix typecasting, add new line at EoF