Fixed possible crashes