Fix possible race condition crash