Fix possible crashes