Fix several crashes