added additional functionality to animate function