fixed friend_index nested loop