9 handed SnG How to play mid pocket pair in bubble
Recently I lost 2 small stakes (3+0.30 and 4+0.40) SnGs on the bubble in a row both because I called all in with a pocket pair, only to have the villain turn over a higher one. In both circumstances I was around the middle of the table in terms of stack size and lost to one of the slightly larger stacks. At this level players are pretty bad so I usually steal lots of blinds and small pots on the flop from the weaker players, which keeps my stack decently sized even though I usually don't knock out any players and play extremely few hands to showdown (and I usually lose those after someone calls my bets but checks it down after I stop betting).
During the first game, I raised UTG with 99 to 3.5 BB and the big blind put me all in. I called and he showed aces. In hindsight this was a big mistake because the BB has been playing weak and folded or limped lots of hands, so when he shoved me I should've known he was on TT+ AQ+.
During the 2nd game, I got 77 on the button the the CO went all in. He was an aggressive player who all in'd a couple times before and made frequent steal attempts so I figured there was a good chance he had a lower pocket pair or something like Ax. I called and he turned over 88.
What should I have done in the 2nd situation, and in these places in general, playing mid pocket pairs on the bubble? I feel like even if my opponent merely called and not went all in and overcards came on the flop I would not really know what to do and would just try to take the pot with a cbet, and if that failed, try to lose the least money possible.