change loop to setInterval