Added error checking for failed file read