Fix crashes and concurrency issues