Dynamically appending to byte array to avoid index out of bounds error.