Fix possible nil reference error