Fixed some possible crashes