more loop stuff and clean up