Move creation of bytearray out of loop.