refactor out duplicate inline membership code

Pull out the membership creation and checking code to shared methods.