Revert "Revert "Fix crash""

This reverts commit c23ec207dd54e94e457a5efc9482fa1feb0bade1.