Fixed file reading functionality. Added error checks for file reading errors.