Fix TypeError due to undefined variable