Use local refs to prevent race condition-induced crashes