fixed code so that consecutive frames are used