Refactored animation code.