changed forloop to make it work