Added safeguards against loading invalid data.