Code used for timer events and animation