extract buffer_length to method