Loop moved to correct location