rewrote popup function

now return null if not found, and accepts a function param