fixed bug with length not being updated properly