remove superfluous length check
use a ringbuffer-like thingy instead of allocating on the stack