Fixed several unusual crashes