Fix detection of last frame.