Turn animation into a function and add comments