works without looping the buffer