Fix reference error in some cases