Improve animation code