Fixed a bug that sometimes caused the game to crash