Added some defence for file corruption