@yuhunglin why do we need `tmpSize`? Can't we just use `tmpData.length`?

also not a big fan of the `tmp`, perhaps remove it?