Fixed crash caused by not setting delegate references to nil.