fixup pointer initialization and off-by-one