The index function was doing the opposite of what it should be doing.  I fixed that and added the frame function which returns the frame for a given index.