made a more advanced looping script