Some code to improve performance during animation