Fixed a few crash bugs