added requestAnimationFrame for updating the UI