added code for animation loop