Add new safety checks so we have fewer seg faults.