Speed improvements to getFrameClosest