changed loop syntax to be less confusing