finally fixed problem reading length out of bytes