Use events instead of setInterval