Fixed various crashes