Here you loned from friend1+friend2 is = 480 only; that is equal to what you purchased + remaining balance =450+30=480.
don't calculate your loaned amount and remaining balance

=240+240+30=510 is wrong
=240+240=450+30 is correct