added a for loop to deal with the first chunk problem