using visual_index so that popup doesn't go out of view
comment added - caution of popup going out of view
removed actual_height since removed from window
added visual_index for popups
removed unused stuff
removed a lot of dead stuff