Refined implementation to use animation system, and fixed some structural errors.