I refactored out the common code so that it's simpler. The rest of the code looks unique to me for both $pull and $push, so I'm not sure if I could shrink it more.