don't trash input byte array, simplify code