Added fread return value check