changed loop to be more readable