Refactoring NextFrameFunction