Implemented better solution that generates different keyframes based on loops