moved the popover logic from the main view controller to legend view controller