Added code comments and minor code reorganization of animation function module.