Fixed several crashes