Only empty stack periodically. Also switch from setTimeout to setInterval