pull out membership processing into it's own function

cuts down duplicate code a bit