added length buffer handling.