Adding check for fread result
Better handling of timeout