It seems that Bytes.toBytes could be moved outside the loop.