check that indices won't overflow, closes #212