Improved popup-lookup to handle index variables and primes