Changed frame index system to avoid possible race conditions from use of wait