refactored and tested AvatarLookup

less array copying

Avoid N queries
Merge pull request #901 from xtream/master

Refactored AvatarLookup