implemented requestAnimationFrame for consistent frame rate