Updated the animation function and pg mainloop