Refactored the way to create an animation frame loop.