fixed to use setTimeout instead of setInterval.