fixing invalid bytesRemaining