fixing index off end, bit by bit