Refactoring keyframes handler