fixing code from unnecesairy looping