Changing Loop from setInterval to setTimeout