Re-arranged the code, and added a maxnumfriends counter

As mentioend in #271 - an internal friends counter is added.