Is there an off-by-one error here? The first time around this loop, you'll read `data[dataLen]`, which seems like it's one past the end, unless I'm misunderstanding the meaning of `dataLen`.