Changed main loop from interval to recurrent timeout