proper check, and use fgest instead of getc