Fixed logic for positioning the popups