Added error handling and file format validation.