Better setInterval/clearInterval for javascript