add check for n being greater than size of frames vector