added visibility logic to pagination