Finally, fixed the crashes at app exit!