fix bug with total length not being respected