Refactored to take advantage of renderAnimationFrame