Fixed unexpected runtime errors