Reverted abbreviation of communityvisibilitystate
More tidying, changed some variable names, added debugging information.