Fixed bug that caused crashes