Fix various crashes