Improvement of getFriends function