refactored code in animation-cpp