use of the setInterval method to avoid browser freezing