add some more loop logic