Fixing a bug that would sometimes crash the program