added more functionality to looping