replaced if with for logic