Fixed loops properly (finally!)