Figured out the bug.  It's because I'm not using zero-based indexes internally. Hm.