Modified for Friend Algorithm